import { generate } from "../dist/index.js";

await generate({
    outPath: "./generate.js",
    outType: 'js',
    database: {
        type: 'dm',
        host: "10.30.50.70",
        port: 5236,
        user: "SYSDBA",
        password: "SYSDBA",
        database: "GOV_QTJH",
        table: "T_DICTIONARY",
    },
    transformer: (rows) => {
        const map = new Map();
        rows.forEach((item) => {
            const dictionType = item["DICTIONARY_TYPE"]
            const dict = map.get(dictionType);
            if (!dict) {
                map.set(dictionType, {
                    name: dictionType,
                    comment: item["DICTIONARY_MEMO"],
                    select: [
                        {label: item["DICTIONARY_VALUE"], value: item["DICTIONARY_CODE"]},
                    ],
                });
            } else {
                dict.select.push({
                    label: item["DICTIONARY_VALUE"],
                    value: item["DICTIONARY_CODE"],
                });
            }
        });

        return Array.from(map.values());
    }
});
